package com.hbnu.zhouxunfa;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author: 周训发
 * @CreateTime: 2025-10-29
 * @Description: 服务端
 * @Version: 1.0
 */

public class Server {
    public static void main(String[] args) {
        //TCP 接收数据
        try {
            ServerSocket ss = new ServerSocket(8080);
            Socket socket = ss.accept();
            InputStream is = socket.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            int len;
            while ((len=isr.read())!=-1){
                System.out.println((char) len);
            }

            OutputStream os = socket.getOutputStream();
            String str = "收发成功";
            os.write(str.getBytes());

            socket.close();
            ss.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
